package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.entity.DishComment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishCommentMapper extends BaseMapper<DishComment> {
    
    /**
     * 获取菜品的评分统计信息
     * @param dishId 菜品ID
     * @return 评分统计信息
     */
    @Select("SELECT " +
            "COUNT(*) as total_comments, " +
            "AVG(rating) as average_rating, " +
            "COUNT(CASE WHEN rating = 5 THEN 1 END) as five_star_count, " +
            "COUNT(CASE WHEN rating = 4 THEN 1 END) as four_star_count, " +
            "COUNT(CASE WHEN rating = 3 THEN 1 END) as three_star_count, " +
            "COUNT(CASE WHEN rating = 2 THEN 1 END) as two_star_count, " +
            "COUNT(CASE WHEN rating = 1 THEN 1 END) as one_star_count " +
            "FROM dish_comment " +
            "WHERE dish_id = #{dishId} AND status = 1 AND deleted = 0")
    DishComment selectRatingStatistics(Long dishId);
} 